using UnityEngine;

public class IS_Bullet_Collision_Script : MonoBehaviour
{
    /* 碰撞发生的条件:
            1.碰撞双方都包含Collider碰撞器组件
            2.需要其中一方包含RigidBody刚体组件
     */
    
    /* 碰撞开始时调用一次 */
    private void OnCollisionEnter(Collision other)
    {
        Debug.Log("碰撞开始...");
        MeshRenderer meshRenderer = other.gameObject.GetComponent<MeshRenderer>();
        meshRenderer.material.color = Color.red;
        // 碰撞的点个数
        // other.contactCount
        // other.contacts
        for (int i = 0; i < other.contactCount; i++)
        {
            Vector3 tempPos = other.contacts[i].point;
            // 在接触点位置生成对象
            GameObject tempObj = new GameObject("Point"); 
            tempObj.transform.position = tempPos;
        }
    }
    
    /* 保持碰撞期间会一直调用，每帧一次 */
    private void OnCollisionStay(Collision other)
    {
    }

    /* 碰撞结束时调用一次 */
    private void OnCollisionExit(Collision other)
    {
        Debug.Log("碰撞结束...");
        MeshRenderer meshRenderer = other.gameObject.GetComponent<MeshRenderer>();
        meshRenderer.material.color = Color.blue;
    }
}